1. Field of the Invention
This invention relates to the field of computer program development and execution, and more particularly to a method and apparatus for customizing characteristics of strokes used in the generation of computer graphics images.
2. Background Art
In a computer system, it is often desired to create images for outputting via a computer display, a printer, or other output device. Two types of image formats used in computer graphics are xe2x80x9cbit-mappedxe2x80x9d images and xe2x80x9cvectorxe2x80x9d images. A bit-mapped image (or xe2x80x9crasterxe2x80x9d image) is stored as a matrix of individual pixels having a defined color and brightness. A vector image is stored as a series of lines or curves (e.g. Bezier curves) having specified endpoints and characteristics such as color, line-style, width, etc. To output a bit-mapped image via a display device, each pixel of the image is mapped to a corresponding pixel of the display. To output a vector image, each line segment of the vector image must first be converted to a corresponding group of pixels that can be mapped to the display.
The lines or curve segments of a vector image may represent outlines of objects, that, when displayed (or xe2x80x9cdrawnxe2x80x9d) on an output device, are to be filled with a certain pattern or color. Alternatively, the lines or curves may represent a trajectory or path that, when displayed, is traversed by a series of xe2x80x9cstrokesxe2x80x9d that can be compared to the strokes of a pen or brush. Filling an outline is a fairly straightforward process. Stroking a path or trajectory is more complex, involving determination of the stroke characteristics, such as the shape of the stroke and the style of the pen, for each line or curve segment. Examples of stroke shapes include basic stroke shapes and calligraphic stroke shapes. Examples of pen styles include thick or thin, solid or dashed, etc.
The capability for converting vector images to raster images for display on an output device (i.e. by filling outlines or stroking along stroke trajectories) may be provided by an operating system, or, more typically, by an xe2x80x9capplication program interfacexe2x80x9d (API) that provides additional functionality over the operating system. Usually the stroke styles available are limited to some fixed predetermined number provided by the operating environment (operating system and/or API""s) of the computer system.
In many environments, when a stroke trajectory is to be drawn by an operating system or API, it is first converted to an outline path called a xe2x80x9cstroke outline.xe2x80x9d This outline is then filled using the same fill capability used to fill other outlined objects. The stroke outline is created by xe2x80x9cstrokingxe2x80x9d along the segments of the stroke trajectory with a logical pen having the characteristics defined for that segment.
The series of pen strokes used to define the stroke trajectory are drawn by the computer. A program developer generally takes advantage of a stroke interface that is part of an API to provide the characteristics of the stroke that is to be used to create an image by the application program being developed. Such an interface permits the developer to select from among the available characteristics of the logical pen provided by the API.
In the prior art most APIs provide a single hard coded algorithm for determining and implementing stroke attributes and characteristics. An interface is provided that allows the application program created by the developer to select from a menu of provided attributes. A hard coded algorithm is then implemented to turn the stroke trajectory into a fillable stroke outline using the selected characteristics. A stroke trajectory is presented to the algorithm and a fillable outline is returned. The fillable outline is then filled using a standard filling algorithm to render the desired strokes.
A disadvantage of the prior art methods of providing a hard coded implementation (API interface and algorithm) is the lack of flexibility to developers and users. Consider a developer who wishes to create a program that uses stroke attributes or characteristics other than those provided in the basic algorithm. For example, it may be desired to have calligraphic style strokes, automatic placement of arrows on the end of lines, or other custom features. To accomplish this in the prior art, the new features must be implemented (if possible) as a manipulation of the stroke outline returned by the basic algorithm. This involves extra rendering steps, additional coding, can degrade performance and in some cases, prevent some desired features.
Alternatively, a developer could implement a custom stroking style by manually turning stroke trajectories into fillable stroke outlines and then using the outline filling API instead of the path stroking API. This has the disadvantage that there is no way to install this custom algorithm into the rendering pipeline so that other arbitrary rendering code which that developer uses, but did not write, will be able to use the custom algorithm.
The invention provides a method and apparatus for customizing and substituting strokes provided by a standard API. In a preferred embodiment, a stroke interface that encapsulates stroking algorithms and interfaces for stroke calculation is provided by an API. The stroke interface is provided in the form of a class. The use of the stroke interface permits additional algorithms and interfaces to be provided as new classes. This allows developers to customize stroke characteristics and attributes. In a preferred embodiment, a basic stroke class contains standard stroke characteristics of a logical pen. These characteristics include line width, end cap shape, line join style, and dash attributes.